#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

#define MAX_N 1001
#define MAX_W 10001

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	int n, W;
	scanf("%d %d", &n, &W);

	int wi[MAX_N], vi[MAX_N];
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &wi[i], &vi[i]);
	}

	int dp[MAX_W] = { 0 };

	memset(dp, 0, sizeof(dp));

	for (int i = 0; i <= n; i++) {
		for (int j = wi[i]; j <= W; j++) {
			dp[j] = max(dp[j], dp[j - wi[i]] + vi[i]);
		}
	}
	printf("%d\n", dp[W]);
	return 0;
}